<#assign menuId=7>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>工厂管理-${Application.systemName!}</title>
<meta
	content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
	name='viewport'>
<!-- bootstrap 3.0.2 -->
<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="../css/font-awesome.min.css" rel="stylesheet"
	type="text/css" />
<!-- Ionicons -->
<link href="../css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="../css/AdminLTE.css" rel="stylesheet" type="text/css" />

<link href="../css/myself.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../css/pagination.css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>

<style type="text/css">

.find-box .find-row .pull-left {
	padding: 0 1px;
}

.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
	vertical-align: middle;
}
.style span{
	border:1px solid #3882ff;
	padding:2px 7px;
	display:inline-block;
	color: #3882ff;
	margin-right: 3px;
	border-radius: 2px;
	margin: 0 5px 5px 0;
}

.style{
	text-align: left;
}
.box-header {
	padding: 10px;
}

.modal-dialog {
	width: 300px;
}

.modal-title {
	font-size: 18px;
}

.modal-body {
	padding: 20px 20px 0;
}

.modal-body table {
	margin: 0 auto;
}
.find-row label{
	margin-right: 10px;
}
			
			
</style>
</head>
<body class="skin-blue">
	<!-- header logo: style can be found in header.less -->
	<#include "../header.html"/>
	<div class="wrapper row-offcanvas row-offcanvas-left">
		<!-- Left side column. contains the logo and sidebar -->
		<#include "../menu.html" />

		<!-- Right side column. Contains the navbar and content of the page -->
		<aside class="right-side">
			<section class="content-header">
				<h1>工厂管理</h1>
				<div class="pull-right" style="position: absolute; top: 10px; right: 20px;">
				<#if (Session["permisionMap"]["F601"]??)>
				        
					<button id="addFactory" type="button" class="btn btn-primary">新增工厂</button>
					</#if>
				</div>
				<hr style="margin: 10px 0 0 0"/>
			</section>
			<section class="content">
				<div class="row">
					<div class="col-md-12">
						<div class="box">
							<div class="clearfix search-div center">
							
							
							
							<div class="search1">
					            	<form action="list" method="get">
							       		<ul style="padding: 0"> 
							       			<li>
												<input id="factoryName" name="name" value="${name!}" type="text" placeholder="输入工厂名" style="padding: 6px;" />
							       			</li>
							       			<li>
												<input id="linkman" name="linkman" value="${linkman!}" type="text" placeholder="联系人" style="padding: 6px;" />
							       			</li>
							       			<li>
												<select id="cooperationCondition" name="cooperationCondition" class="input-md" id="category" style="padding:6px;"></select>
							       			</li>
							       		 	<li>
							       		 		<select id="personAmount" name="personAmount" value="${personAmount!}" class="input-md" id="level" style="padding:6px;"></select>
							       		 	</li>
							       		 	<li>
							       		 		<input id="address" name="address" value="${address!}" class="click" type="text" readonly="readonly" placeholder="地址" style="padding: 6px;" data-toggle="modal" data-target="#myModal" data-backdrop="static" />
							       		 			<div class="modal fade" id="myModal" tabindex="-1"
													role="dialog" aria-labelledby="myModalLabel"
													aria-hidden="true">
													<div class="modal-dialog">
														<div class="modal-content">
															<div class="modal-header">
																<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
																<h4 class="modal-title" id="myModalLabel">选择地址</h4>
															</div>
															<div class="modal-body" style="text-align: center;">
																<table>
																	<tr>
																		<td style="border: 0;">
																			<div class="form-group">
																				<select id="province" class="form-control sel1">
																					<option value="0">请选择</option>
																				</select>
																			</div>
																		</td>
																		<td style="border: 0;">
																			<div class="form-group">
																				<select id="city" class="form-control sel2">
																					<option value="0">请选择</option>
																				</select>
																			</div>
																		</td>
																		<td style="border: 0;">
																			<div class="form-group">
																				<select id="area" class="form-control sel3">
																					<option value="0">请选择</option>
																				</select>
																			</div>
																		</td>
																	</tr>
																</table>
															</div>
															<div class="modal-footer">
																<button type="button" class="btn btn-primary hid_click" data-dismiss="modal">
																	确定
																</button>
																<button type="button" class="btn btn-default hid_click" data-dismiss="modal">
																	取消
																</button>
															</div>
														</div>
														
													</div>
													
												</div>
							       		 	</li>
							       			<li>
							       				<div>
				                                    <button type="submit" class="btn btn-primary btn-sm">搜索</button>
		                                		</div>
							       			</li>
							       		</ul>
							       		</form>
							       	</div> 
							</div>
							<!-- /.box-header -->

							<div class="clearfix  center">
								<div class="clearfix"></div>
								<table class="table table-bordered text-center">

									<tr>
										<th width="19%" style="border: 0;">基本信息</th>
										<th width="19%" style="border: 0;">梭织类型</th>
										<th width="19%" style="border: 0;">针织类型</th>
										<th width="19%" style="border: 0;">毛衣类型</th>
										<th width="12%" style="border: 0;">合作条件</th>
										<th width="12%" style="border: 0;">操作</th>
									</tr>

								</table>
								<#list factoryDtos as factoryResult>
								<table class="table table-bordered order-list">
									<tr>
										<td class="left-text" style="font-weight: bold;"><a style="color: black"
											href="showDetailPage?factoryId=${factoryResult.id}">
												工厂编号： <span class="number">${factoryResult.code!}</span>
										</a></td>
									</tr>
									<tr>
										<td>
											<table width="100%">
												<tr>
													<td width="19%"><a
														href="showDetailPage?factoryId=${factoryResult.id}">
															<div id="name" style="margin: 0 0 15px 10px;">
																${factoryResult.name!}</div>
													</a> <#list factoryResult.factoryContacts as factoryContact>
														<div style="margin-left: 10px;">
															<i class="iconfont">&#xe6f5;</i>
															联系人：${factoryContact.linkman!}
														</div>
														<div style="margin-left: 10px;">
															<i class="iconfont">&#xe6f3;</i>
															联系方式：${factoryContact.contact!}
														</div> </#list></td>
													<td class="style" width="19%"><#list
														factoryResult.tattingStyle as constant1> <span>${constant1.name}</span>
														</#list>
													</td>
													<td class="style" width="19%"><#list
														factoryResult.wovenStyle as constant2> <span>${constant2.name}</span>
														</#list>
													</td>
													<td class="style" width="19%"><#list
														factoryResult.sweaterStyle as constant3> <span>${constant3.name}</span>
														</#list>
													</td>
													<td width="12%" class="text-center" style="text-align: center">
														${factoryResult.cooperation_condition!}</td>
													<td width="12%" class="text-center" style="text-align: center"> 
													<#if (Session["permisionMap"]["F602"]??)>
														<div>
															<a href="showModifyPage?factoryId=${factoryResult.id!}">编辑</a>
														</div>
														</#if>
														<#if (Session["permisionMap"]["F603"]??)>
														<div>
															<a id="remove"
																href="javascript:deleteFactory('${factoryResult.id!}')">删除</a>
														</div> 
														</#if>
													</td>
												</tr>
											</table>
										</td>
									</tr>
								</table>
								</#list>
								<div class="box-footer clearfix">
									<ul class="pagination pagination-sm no-margin pull-right">
										<#if splitPage??> ${splitPage?replace("{url}","${url!}")}
										</#if>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
		</aside>
		<!-- /.right-side -->
	</div>
	<!-- ./wrapper -->

	<!-- jQuery UI 1.10.3 -->
	<script src="../js/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
	<!-- Bootstrap -->
	<script src="../js/bootstrap.min.js" type="text/javascript"></script>
	<!-- AdminLTE App -->
	<script src="../js/AdminLTE/app.js" type="text/javascript"></script>
	<!-- AdminLTE for demo purposes -->
	

	<script type="text/javascript">
			var model={};
			$(function(){
				/* swal("Good job!", "You clicked the button!", "success"); */
				$('#addFactory').click(addFactory);
				//获取工人人数列表
				getPersonAmount();
				//获取合作条件列表
				getCooperationCondition()
				//获取所有省数据
	        	getAllProvince();
				//获取对应的市
				getCityByParentId(model.provinceId);
				//获取对应的区县
				getAreaByParentId(model.cityId);
	        	$('#province').change(provinceOnSelect);
	        	$('#city').change(cityOnSelect);
			});
			
			
			$('.hid_click:eq(0)').click(function() {
				var address=""
				if($("#province").find("option:selected").val()!=0){
					address+=$("#province").find("option:selected").text()+",";
				}
				if($("#city").find("option:selected").val()!=0){
					address+=$("#city").find("option:selected").text()+",";
				}
				if($("#area").find("option:selected").val()!=0){
					address+=$("#area").find("option:selected").text()+",";
				}
				address = address.substring(0,address.length-1);
				$('.click').val(address);
				$('.hid_address').hide();
				
			});
			
			//删除工厂
			function deleteFactory(id){
				confirm("确定要删除,删除后将无法恢复?",function(flag){
					if(flag){
						$.ajax({
	                		url:"../factory/deleteFactory",
	                		data:{"factoryId":id},
	                		type:"post",
	                		success:function(result){
	                			if(result.head.respCode=="0000000"){
	                				
	                				if(result.body=="删除成功"){
	                					success("工厂删除成功",function(){
	                						window.location.href = 'list';
	                					}) 
	                				}else{
	                					alert(result.body);
	                				}
	                			}else{
	                				alert(result.body);
	                			}
	                		}
	                	});
					}
				});
			}
			
			function addFactory() {
				window.location.href = 'showAddPage';
			}
			
			//获取工厂人数列表
	        function getPersonAmount(){
	        	var constants = getConstant("scm_factory-person_amount");
	        	var view = $('#personAmount');
	        	view.empty();
	        	var option = $('<option value="0">请选择工厂人数</option>')
	        	view.append(option);
	        	for(var i=0;i<constants.length;i++){
	        		option = $('<option value="'+constants[i].name+'">'+constants[i].name+'</option>');
	        		view.append(option);
	        	}
	        	<#if personAmount??>
	        	$('#personAmount').val("${personAmount!}");
	        	</#if>
	        }
			
	      //获取合作条件
	        function getCooperationCondition(){
	        	var constants = getConstant("scm_factory-cooperation_condition");
	        	var view = $('#cooperationCondition');
	        	view.empty();
	        	var option = $('<option value="0">请选择合作条件</option>')
	        	view.append(option);
	        	for(var i=0;i<constants.length;i++){
	        		option = $('<option value="'+constants[i].name+'">'+constants[i].name+'</option>');
	        		view.append(option);
	        	}
	        	<#if cooperationCondition??>
	        	$('#cooperationCondition').val("${cooperationCondition!}");
	        	</#if>
	        }
	      
	        //根据分类条件查询所有的常量列表
	        function getConstant(category){
	        	var constants={};
	        	var url = "../constant/getConstantByCategory";
	        	var data = {"category":category};
	        	//关闭ajax异步
	        	$.ajaxSettings.async = false;
	        	$.getJSON(url,data,function(result){
	        		if(result.head.respCode="0000000"){
	        			constants = result.body.rows;
	        		}
	        	});
	        	//开启ajax异步
	        	$.ajaxSettings.async = true;
	        	return constants;
	        }
	        
	      //获取所有省数据
	        function getAllProvince(){
	        	var url = "../area/province";
	        	$.ajaxSettings.async = false;
	        	$.getJSON(url,function(result){
	        		if(result.head.respCode=="0000000"){
	        			var provinces = result.body.rows;
	        			var view = $('#province');
	        			view.empty();
	        			var option = $('<option value="0">请选择</option>');
	        			view.append(option)
	        			for(var i=0;i<provinces.length;i++){
	        				if(provinces[i].areaName=='${province!}'){
	        					option = $('<option selected="selected" value="'+provinces[i].areaId+'">'+provinces[i].areaName+'</option>');
	        					model.provinceId = provinces[i].areaId;
	        				}else{
	        					option = $('<option value="'+provinces[i].areaId+'">'+provinces[i].areaName+'</option>');
	        				}
	        				view.append(option);
	        			}
	        		}
	        	});
	        	$.ajaxSettings.async = true;
	        }
	        
	      //从服务端根据parentId获取对应的市列表
	        function getCityByParentId(parentId){
	        	var url = "../area/cityOrArea";
	        	var data = {"parentId":parentId};
	        	$.ajaxSettings.async = false;
	        	$.getJSON(url,data,function(result){
	        		if(result.head.respCode=="0000000"){
	        			var citys = result.body.rows;
	        			var view = $('#city');
	        			view.empty();
	        			var option = $('<option value="0">请选择</option>');
	        			view.append(option)
	        			for(var i=0;i<citys.length;i++){
	        				if(citys[i].areaName=='${city!}'){
	        					option = $('<option selected="selected" value="'+citys[i].areaId+'">'+citys[i].areaName+'</option>');
	        					model.cityId = citys[i].areaId;
	        				}else{
	        					option = $('<option value="'+citys[i].areaId+'">'+citys[i].areaName+'</option>');
	        				}
	        				view.append(option);
	        			}
	        		}
	        	});
	        	$.ajaxSettings.async = true;
	        }

	      //从服务端根据parentId获取对应的区县列表
	        function getAreaByParentId(parentId){
	        	console.log(parentId);
	        	var url = "../area/cityOrArea";
	        	var data = {"parentId":parentId};
	        	$.ajaxSettings.async = false;
	        	$.getJSON(url,data,function(result){
	        		if(result.head.respCode=="0000000"){
	        			var areas = result.body.rows;
	        			var view = $('#area');
	        			view.empty();
	        			var option = $('<option value="">请选择</option>');
	        			view.append(option)
	        			for(var i=0;i<areas.length;i++){
	        				if(areas[i].areaName=='${area!}'){
	        					option = $('<option selected="selected" value="'+areas[i].areaId+'">'+areas[i].areaName+'</option>');
	        				}else{
	        					option = $('<option value="'+areas[i].areaId+'">'+areas[i].areaName+'</option>');
	        				}
	        				view.append(option);
	        			}
	        		}
	        	});
	        	$.ajaxSettings.async = true;
	        }
	        
	      //省下拉框选中监听事件
	        function provinceOnSelect(){
	        	if($(this).val()!="0"){
	        		//省选中后清空所有
	        		cleanArea();
	        		var provinceId = $(this).val();
	        		//从服务端获取对应的城市列表
	        		getCityByParentId(provinceId);
	        	}
	        	if($(this).val()=="0"){
	        		cleanCity();
	        		cleanArea();
	        	}
	        }

	        //市下拉框选中监听事件
	        function cityOnSelect(){
	        	if($(this).val()!="0"){
	        		var cityId = $(this).val();
	        		//从服务端获取对应的区县列表
	        		getAreaByParentId(cityId);
	        	}
	        	if($(this).val()=="0"){
	        		cleanArea();
	        	}
	        }


	        //清空市
	        function cleanCity(){
	        	var view = $('#city');
	        	view.empty();
	        	var option = $('<option value="0">请选择</option>');
	        	view.append(option);
	        }

	        //清空区县
	        function cleanArea(){
	        	var view = $('#area');
	        	view.empty();
	        	var option = $('<option value="0">请选择</option>');
	        	view.append(option);
	        }
			
	        $('.sidebar-menu li').click(function() {
       			$(this).addClass('active');
       		});
		</script>
</body>
</html>

